from pymongo import MongoClient
from sentence_transformers import SentenceTransformer

client = MongoClient('mongodb://localhost:27017/')
db = client['knowledge_db']
model = SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')

def search_vector_db(query):
    query_vec = model.encode(query).tolist()
    
    results = db.vectors.aggregate([
        {"$vectorSearch": {
            "queryVector": query_vec,
            "path": "vector",
            "numCandidates": 100,
            "limit": 3,
            "index": "vector_index"
        }}
    ])
    
    return [doc['text'] for doc in results]